package com.giaothong.model;

import org.json.JSONObject;

import com.giaothong.config.Define;
import com.giaothong.model.entity.UserEntity;
import com.giaothong.utils.JSONUtil;

public class ModelLoginRegisterRequest {
	private int code;
	private UserEntity userEntity;
	/*
	 * setter & getter
	 */
	public void setCode(int code) {
		this.code = code;
	}

	public void setUserEntity(UserEntity userEntity) {
		this.userEntity = userEntity;
	}

	public int getCode() {
		return code;
	}

	public UserEntity getUserEntity() {
		return userEntity;
	}

	/**
	 * contructor
	 */
	public ModelLoginRegisterRequest() {
		setDefautValue();
	}

	public ModelLoginRegisterRequest(JSONObject jsonObject) {
		setDefautValue();
		if (jsonObject == null)
			return;
		this.code = JSONUtil.intTryGetValue(jsonObject, Define.CODE);
		if (this.code != Define.CODE_SUCCESSFULL)
			return;
		this.userEntity = new UserEntity(JSONUtil.jsonObjectTryGetValue(jsonObject, Define.DATA));
	}
	private void setDefautValue() {
		this.code = -1;
		this.userEntity = new UserEntity();
	}
}
